package com.Xingcang_Dianxue.WhutBank.Controllers.Client;

import com.Xingcang_Dianxue.WhutBank.Models.Model;
import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;

import java.net.URL;
import java.util.ResourceBundle;


public class ProfileController implements Initializable {
    @FXML
    private Label ch_acc_bal;

    @FXML
    private Label ch_acc_date;

    @FXML
    private Label ch_acc_num;

    @FXML
    private Label ch_transaction_limit;

    @FXML
    private Label checking_acc_num;

    @FXML
    private Label checking_balance;

    @FXML
    private Text user_name;
    @FXML
    private AnchorPane ch_container;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        bindData();
    }

    // 将用户信息绑定到界面上显示
    private void bindData() {
        user_name.textProperty().bind(Model.getInstance().getClient().userNameProperty());
        // 判断用户是否有银行卡
        if (Model.getInstance().getClient().getCheckingAccount() != null) {
            // 银行卡号
            String[] checking_num = Model.getInstance().getClient().getCheckingAccount().getAccountNumber().split(" ");
            checking_acc_num.textProperty().bind(Bindings.concat(checking_num[0], " ", checking_num[1], " ", checking_num[2], " ", checking_num[3]));
            ch_acc_num.textProperty().bind(Bindings.concat(checking_num[0], " ", checking_num[1], " ", checking_num[2], " ", checking_num[3]));
            // 银行卡转账额度
            ch_transaction_limit.textProperty().bind(Bindings.concat("￥").concat(Model.getInstance().getClient().getCheckingAccount().transactionLimitProperty()));
            // 银行卡余额
            checking_balance.textProperty().bind(Bindings.concat("￥").concat(Model.getInstance().getClient().getCheckingAccount().balanceProperty()));
            ch_acc_bal.textProperty().bind(Bindings.concat("￥").concat(Model.getInstance().getClient().getCheckingAccount().balanceProperty()));
        } else {
            ch_container.setVisible(false);
        }
    }


}
